const { Service } = require("egg")
class WxUserService extends Service {
  async list(pageSize, pageNum, where) {
    const data = await this.app.mysql.select("egg_wxuser", {
      where,
      orders: [
        ["id", "desc"],
        ["nickName", "desc"],
      ],
      offset: (pageNum - 1) * pageSize,
      limit: pageSize,
    })

    const total = await this.app.mysql.count("egg_wxuser", where)
    data.map((item) => {
      delete item.openid
      delete item.session_key
    })
    return { data, total }
  }

  async single(id) {
    const result = await this.app.mysql.get("egg_wxuser", { id })
    return result
  }
  async create(userInfo) {
    const result = await this.app.mysql.insert("egg_wxuser", userInfo)
    return result
  }
  async openIdSingle(openid) {
    const result = await this.app.mysql.get("egg_wxuser", { openid })
    return result
  }
}
module.exports = WxUserService
